package org.jivesoftware.smackx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.packet.DataForm;
import org.jivesoftware.smackx.packet.DataForm.Item;
import org.jivesoftware.smackx.packet.DataForm.ReportedData;

public class ReportedData
{
  private List<Column> columns = new ArrayList();
  private List<Row> rows = new ArrayList();
  private String title = "";

  private ReportedData(DataForm paramDataForm)
  {
    Iterator localIterator1 = paramDataForm.getReportedData().getFields();
    if (!(localIterator1.hasNext()))
      localIterator2 = paramDataForm.getItems();
    while (true)
    {
      while (!(localIterator2.hasNext()))
      {
        this.title = paramDataForm.getTitle();
        return;
        FormField localFormField1 = (FormField)localIterator1.next();
        this.columns.add(new Column(localFormField1.getLabel(), localFormField1.getVariable(), localFormField1.getType()));
      }
      DataForm.Item localItem = (DataForm.Item)localIterator2.next();
      localArrayList1 = new ArrayList(this.columns.size());
      localIterator3 = localItem.getFields();
      if (localIterator3.hasNext())
        break;
      this.rows.add(new Row(localArrayList1));
    }
    FormField localFormField2 = (FormField)localIterator3.next();
    ArrayList localArrayList2 = new ArrayList();
    Iterator localIterator4 = localFormField2.getValues();
    while (true)
    {
      while (!(localIterator4.hasNext()))
        localArrayList1.add(new Field(localFormField2.getVariable(), localArrayList2));
      localArrayList2.add((String)localIterator4.next());
    }
  }

  public static ReportedData getReportedDataFrom(Packet paramPacket)
  {
    ReportedData localReportedData;
    PacketExtension localPacketExtension = paramPacket.getExtension("x", "jabber:x:data");
    if (localPacketExtension != null)
    {
      DataForm localDataForm = (DataForm)localPacketExtension;
      if (localDataForm.getReportedData() != null)
        localReportedData = new ReportedData(localDataForm);
    }
    while (true)
    {
      return localReportedData;
      localReportedData = null;
    }
  }

  public void addColumn(Column paramColumn)
  {
    this.columns.add(paramColumn);
  }

  public void addRow(Row paramRow)
  {
    this.rows.add(paramRow);
  }

  public Iterator<Column> getColumns()
  {
    return Collections.unmodifiableList(new ArrayList(this.columns)).iterator();
  }

  public Iterator<Row> getRows()
  {
    return Collections.unmodifiableList(new ArrayList(this.rows)).iterator();
  }

  public String getTitle()
  {
    return this.title;
  }

  public static class Column
  {
    private String label;
    private String type;
    private String variable;

    public Column(String paramString1, String paramString2, String paramString3)
    {
      this.label = paramString1;
      this.variable = paramString2;
      this.type = paramString3;
    }

    public String getLabel()
    {
      return this.label;
    }

    public String getType()
    {
      return this.type;
    }

    public String getVariable()
    {
      return this.variable;
    }
  }

  public static class Field
  {
    private List<String> values;
    private String variable;

    public Field(String paramString, List<String> paramList)
    {
      this.variable = paramString;
      this.values = paramList;
    }

    public Iterator<String> getValues()
    {
      return Collections.unmodifiableList(this.values).iterator();
    }

    public String getVariable()
    {
      return this.variable;
    }
  }

  public static class Row
  {
    private List<ReportedData.Field> fields = new ArrayList();

    public Row(List<ReportedData.Field> paramList)
    {
      this.fields = paramList;
    }

    private Iterator<ReportedData.Field> getFields()
    {
      return Collections.unmodifiableList(new ArrayList(this.fields)).iterator();
    }

    public Iterator getValues(String paramString)
    {
      Iterator localIterator2;
      Iterator localIterator1 = getFields();
      if (!(localIterator1.hasNext()))
        localIterator2 = null;
      while (true)
      {
        ReportedData.Field localField;
        do
        {
          return localIterator2;
          localField = (ReportedData.Field)localIterator1.next();
        }
        while (!(paramString.equalsIgnoreCase(localField.getVariable())));
        localIterator2 = localField.getValues();
      }
    }
  }
}